//
//  YWMeHeaderView.m
//  网易新闻
//
//  Created by Yeewii@hotmail.com on 16/6/21.
//  Copyright © 2016年 Yeewii@hotmail.com. All rights reserved.
//

#import "YWMeHeaderView.h"
#import <UIImageView+WebCache.h>
#import "Constants.h"
#import <UIView+SDAutoLayout.h>

#define MEHEADERHEIGH 200
#define ICONHEIGH 60

@implementation YWMeHeaderView
{
    UIImageView *_iconImage;
    UILabel *_alertLabel;
}


+(CGFloat)fixHeaderHeigh;
{
    return MEHEADERHEIGH;
}

-(instancetype)init
{
    if (self = [super init])
    {
        self.backgroundColor = [UIColor redColor];
        _iconImage = [[UIImageView alloc]initWithFrame:CGRectMake((MAINWIDTH-ICONHEIGH)/2.0,(MEHEADERHEIGH-ICONHEIGH)/2.0-20, ICONHEIGH, ICONHEIGH)];
        _iconImage.image = [UIImage imageNamed:@"login_username_icon"];
        _iconImage.userInteractionEnabled = YES;
        UITapGestureRecognizer *loginTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(logTap)];
        [_iconImage addGestureRecognizer:loginTap];
        [self addSubview:_iconImage];
        
        _alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconImage.left, _iconImage.bottom+10, _iconImage.width, 20)];
        _alertLabel.textColor = [UIColor whiteColor];
        _alertLabel.text = @"立即登录";
        _alertLabel.textAlignment = 1;
        _alertLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_alertLabel];
        
    }
    return self;
}

-(void)logTap
{
    if (self.wxLogin)
    {
        _wxLogin();
    }
}
-(void)setModel:(YWWeChatModel *)model
{
    _model = model;
    [_iconImage sd_setImageWithURL:[NSURL URLWithString:_model.headimgurl] placeholderImage:[UIImage imageNamed:@"login_username_icon"]];
    _alertLabel.text = _model.nickname?_model.nickname:@"立即登录";
    _iconImage.userInteractionEnabled = !_model.headimgurl;
}
@end
